<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="考生姓名" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="考生姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="examineeList">
      <el-table-column label="答卷编号" align="center" prop="id" />
      <el-table-column label="考生" align="center" prop="userName" />
      <el-table-column label="阅卷状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.grade_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="submitTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="阅卷人" align="center" prop="gradeName" />
      <el-table-column label="阅卷时间" align="center" prop="gradeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gradeTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总得分" align="center" prop="totalScore" />
      <el-table-column label="评语" align="center" prop="comment" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleMark(scope.row)"
            v-hasPermi="['paper:mark:getExamineeExamInfo']"
          >阅卷</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listExaminee} from "@/api/paper/mark";

export default {
  name: "Examinee",
  dicts: ['grade_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考生答卷总表格数据
      examineeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        paperId: null,
        userId: null,
        status: null,
        submitTime: null,
        gradeId: null,
        gradeTime: null,
        questionOrder: null,
        totalScore: null,
        comment: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询考生答卷总列表 */
    getList() {
      this.loading = true;
      const id = this.$route.params && this.$route.params.id;
      this.queryParams.paperId = id;
      listExaminee(this.queryParams).then(response => {
        this.examineeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        paperId: null,
        userId: null,
        status: null,
        submitTime: null,
        gradeId: null,
        gradeTime: null,
        questionOrder: null,
        totalScore: null,
        comment: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('paper/exam/exportExaminee', {
        ...this.queryParams
      }, `examinee_${new Date().getTime()}.xlsx`)
    },
    /** 阅卷 */
    handleMark: function(row) {
      const id = this.$route.params && this.$route.params.id;
      const examineeId = row.id;
      const userId = row.userId;
      this.$router.push("/mark/markInfo/paper/" + id+"?examineeId="+examineeId+"&userId="+userId);
    }
  }
};
</script>
